package GUI;

import redis.clients.jedis.Jedis;
import swimming.Redis;
import swimming.consumption;
import swimming.manager;
import use.manageruse;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.SQLException;
import java.util.List;

public class password {
    private JPanel panel1;
    private JTextField oldpass;
    private JTextField textField1;
    private JButton 确定Button;
    private JButton 会员卡充值Button;
    private JButton 新会员注册Button;
    private JButton 查询修改会员信息Button;
    private JButton 更改系统密码Button;
    private JButton 查询消费记录Button;
    private JButton 会员卡汇总记录Button;
    private JButton 使用会员卡Button;
    private JTextField newpass;
    private JTextField passnum;
    private JButton 消费记录报表Button;

    public static void iface()
    {
        JFrame frame = new JFrame("游泳馆会员管理系统");
        frame.setSize(500, 400);
        frame.setLocation(400, 200);

        password t1 = new password();
        frame.add(t1.panel1);

        frame.setVisible(true);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
    public password()
    {
        会员卡充值Button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new recharge().iface();
            }
        });
        查询消费记录Button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new consume().iface();
            }
        });
        查询修改会员信息Button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new revise().iface();
            }
        });
        更改系统密码Button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new password().iface();
            }
        });
        新会员注册Button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new VIP().iface();
            }
        });
        会员卡汇总记录Button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new totalVIP().iface();
            }
        });
        使用会员卡Button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new usecard().iface();
            }
        });
        确定Button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                denglu de=new denglu();
                String a=de.getpass();
                manageruse ma=new manageruse();
                String values1 = null;
                String values2 = null;
                Redis j=new Redis();
                Jedis work=j.Redis();
                if(a.equals(textField1.getText()))
                {
                    try {
                        List<manager> list1 = ma.搜索man(textField1.getText());
                        for (manager v : list1) {
                            values1 = v.getPermission();
                            values2=v.getPassword();
                        }
                        if(values2.equals(oldpass.getText()))
                        {
                            if(values1.equals("超级"))
                            {
                                if(passnum.getText().equals("888888")) {
                                    ma.修改(newpass.getText());
                                    work.set("2020081305",newpass.getText());
                                    work.set("2020081321",newpass.getText());
                                    work.close();
                                    JOptionPane.showMessageDialog(null, "密码修改成功", "提示",
                                            JOptionPane.INFORMATION_MESSAGE);
                                }
                                else {
                                    JOptionPane.showMessageDialog(null, "通行密码错误", "提示",
                                            JOptionPane.INFORMATION_MESSAGE);
                                }
                            }
                            else{
                                JOptionPane.showMessageDialog(null, "无权限", "提示",
                                        JOptionPane.INFORMATION_MESSAGE);
                            }
                        }
                        else{
                            JOptionPane.showMessageDialog(null, "密码错误", "提示",
                                    JOptionPane.INFORMATION_MESSAGE);
                        }
                    } catch (SQLException ex) {
                        ex.printStackTrace();
                    }
                }
                else{
                    JOptionPane.showMessageDialog(null, "请联系店长", "提示",
                            JOptionPane.INFORMATION_MESSAGE);
                }
            }
        });
        消费记录报表Button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new baobiao().iface();
            }
        });
    }

    public static void main(String[] args) {
        iface();
    }
}
